package com.share.provider;

import com.share.domain.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;
import java.util.stream.Collectors;

/**
 * author:caifan
 * date:2019/5/26
 */
public class UserProvider {

    public String getUserByCardNo(@Param("cardNo")String cardNo) {
        return new SQL() {{
            SELECT("*");
            FROM("user");
            WHERE("card_no=#{cardNo}");
        }}.toString();
    }

    public String saveUser(User user) {
        return new SQL() {{
            INSERT_INTO("user");
//            INTO_COLUMNS("");
//            INTO_VALUES("");
            VALUES("create_time", "#{createTime}");
            VALUES("nickname", "#{nickname}");
            VALUES("age", "#{age}");
            VALUES("email", "#{email}");
            VALUES("update_time", "#{updateTime}");
            VALUES("username", "#{username}");
            VALUES("status", "#{status}");
            VALUES("card_no", "#{cardNo}");
        }}.toString();
    }

    public String listByEmail(@Param("emailList") List<String> emailList) {

        String emails = emailList.stream().collect(Collectors.joining("','", "'", "'"));
        return new SQL() {{
            SELECT("*");
            FROM("user");
            WHERE("email in (" + emails + ")");
        }}.toString();
    }
}
